package v1

import (
	"gin-vben-admin/internal/constant"
	"gin-vben-admin/internal/model"
)

type SysMenuCreateReq struct {
	AuthId int64 `json:"-" binding:"required"` //创建者

	MenuName  string          `form:"menu_name" json:"menu_name" binding:"required,min=2,max=30" comment:"菜单名称"` //菜单名称
	ParentId  int64           `form:"parent_id" json:"parent_id" binding:"omitempty" comment:"上级菜单"`             //上级菜单
	Sort      int             `form:"sort" json:"sort" binding:"omitempty" comment:"排序"`                         //排序
	Status    constant.Status `form:"status" json:"status" binding:"required,oneof=1 2" comment:"状态"`            //状态 1启用，2禁用
	Icon      string          `form:"icon" json:"icon" binding:"omitempty" comment:"图标"`                         //图标
	Path      string          `form:"path" json:"path" binding:"required,min=2,max=100" comment:"路径"`            //路由路径
	RouteName string          `form:"route_name" json:"route_name" binding:"omitempty" comment:"路由名称"`           //路由名称
	NoCache   int             `form:"no_cache" json:"no_cache" binding:"omitempty,oneof=1 2" comment:"是否缓存"`     //1无需缓存2要缓存
	Component string          `form:"component" json:"component" binding:"omitempty" comment:"组件"`               //组件地址
	Visible   int             `form:"visible" json:"visible" binding:"omitempty,oneof=1 2" comment:"是否显示"`       //是否显示 1显示2不显示
	IsFrame   int             `form:"is_frame" json:"is_frame" binding:"omitempty,oneof=1 2" comment:"是否外链"`     //是否外链 1是2否
}

type SysMenuCreateActionReq struct {
	AuthId     int64           `json:"-" binding:"required"`                                                      //创建者
	MenuName   string          `form:"menu_name" json:"menu_name" binding:"required,min=2,max=30" comment:"菜单名称"` //菜单名称
	ParentId   int64           `form:"parent_id" json:"parent_id" binding:"required,gt=0" comment:"上级菜单"`         //上级菜单
	Sort       int             `form:"sort" json:"sort" binding:"omitempty" comment:"排序"`                         //排序
	Status     constant.Status `form:"status" json:"status" binding:"required,oneof=1 2" comment:"状态"`            //状态 1启用，2禁用
	Permission string          `form:"permission" json:"permission" binding:"required" comment:"权限编码"`            //权限编码， menu_type=2 需要且必填
	ApiIds     []int64         `form:"api_ids"  json:"api_ids"  binding:"omitempty,dive,gt=0" comment:"绑定api"`    //绑定api，menu_type=2 需要
}

type SysMenuListReq struct {
	MenuId int64 `form:"menu_id" form:"menu_id" query:"menu_id" binding:"omitempty"` //菜单id
}

type SysMenuDelReq struct {
}

type SysMenuUpdateReq struct {
	AuthId    int64           `json:"-" binding:"required"`                                                      //创建者
	MenuId    int64           `form:"menu_id" json:"menu_id" binding:"required,gt=0" comment:"菜单id"`             //菜单id
	MenuName  string          `form:"menu_name" json:"menu_name" binding:"required,min=2,max=30" comment:"菜单名称"` //菜单名称
	ParentId  int64           `form:"parent_id" json:"parent_id" binding:"omitempty" comment:"上级菜单"`             //上级菜单
	Sort      int             `form:"sort" json:"sort" binding:"omitempty" comment:"排序"`                         //排序
	Status    constant.Status `form:"status" json:"status" binding:"required,oneof=1 2" comment:"状态"`            //状态 1启用，2禁用
	Icon      string          `form:"icon" json:"icon" binding:"omitempty" comment:"图标"`                         //图标
	Path      string          `form:"path" json:"path" binding:"required,min=2,max=100" comment:"路径"`            //路由路径
	RouteName string          `form:"route_name" json:"route_name" binding:"omitempty" comment:"路由名称"`           //路由名称
	NoCache   int             `form:"no_cache" json:"no_cache" binding:"omitempty,oneof=1 2" comment:"是否缓存"`     //1无需缓存2要缓存
	Component string          `form:"component" json:"component" binding:"omitempty" comment:"组件"`               //组件地址
	Visible   int             `form:"visible" json:"visible" binding:"omitempty,oneof=1 2" comment:"是否显示"`       //是否显示 1显示2不显示
	IsFrame   int             `form:"is_frame" json:"is_frame" binding:"omitempty,oneof=1 2" comment:"是否外链"`     //是否外链 1是2否
}

type SysMenuUpdateActionReq struct {
	AuthId     int64           `json:"-" binding:"required"`                                                      //创建者
	MenuId     int64           `form:"menu_id" json:"menu_id" binding:"required,gt=0" comment:"菜单id"`             //菜单id
	MenuName   string          `form:"menu_name" json:"menu_name" binding:"required,min=2,max=30" comment:"菜单名称"` //菜单名称
	ParentId   int64           `form:"parent_id" json:"parent_id" binding:"required,gt=0" comment:"上级菜单"`         //上级菜单
	Sort       int             `form:"sort" json:"sort" binding:"omitempty" comment:"排序"`                         //排序
	Status     constant.Status `form:"status" json:"status" binding:"required,oneof=1 2" comment:"状态"`            //状态 1启用，2禁用
	Permission string          `form:"permission" json:"permission" binding:"required" comment:"权限编码"`            //权限编码， menu_type=2 需要且必填
	ApiIds     []int64         `form:"api_ids"  json:"api_ids"  binding:"omitempty,dive,gt=0" comment:"绑定api"`    //绑定api，menu_type=2 需要
}

type MenuItem struct {
	model.SysMenu
	Children []*MenuItem `json:"children"`
}

type SysUserMenus struct {
	Menus       []*MenuItem ` json:"menus"`       // 菜单列表
	Permissions []string    ` json:"permissions"` // 权限编码列表
}

//
//func (c *SysMenuCreateReq) Generate(ctx http.Context) *models.SysMenu {
//	model := &models.SysMenu{}
//	model.MenuName = c.MenuName
//	model.Sort = c.Sort
//	model.Status = c.Status
//	model.Icon = c.Icon
//	model.Path = c.Path
//	model.RouteName = c.RouteName
//	model.NoCache = c.NoCache
//	model.ParentId = c.ParentId
//	if c.NoCache == 0 {
//		model.NoCache = constant.Yes
//	}
//	model.Component = c.Component
//	model.Visible = c.Visible
//	if c.Visible == 0 {
//		model.Visible = constant.Yes
//	}
//	model.IsFrame = c.IsFrame
//	if c.IsFrame == 0 {
//		model.IsFrame = constant.No
//	}
//	authId := token.AuthId(ctx)
//	model.CreateBy = authId
//	model.UpdateBy = authId
//	return model
//}
//
//func (c *MenuCreateActionReq) Generate(ctx http.Context) *models.SysMenu {
//	model := &models.SysMenu{}
//	model.MenuName = c.MenuName
//	model.Sort = c.Sort
//	model.Status = c.Status
//	model.Permission = c.Permission
//	model.ParentId = c.ParentId
//	authId := token.AuthId(ctx)
//	model.CreateBy = authId
//	model.UpdateBy = authId
//	return model
//}
//
//func (c *MenuUpdateReq) Generate(model *models.SysMenu, ctx http.Context) *models.SysMenu {
//	model.MenuName = c.MenuName
//	model.Sort = c.Sort
//	model.Status = c.Status
//	model.Icon = c.Icon
//	model.Path = c.Path
//	model.RouteName = c.RouteName
//	model.NoCache = c.NoCache
//	model.ParentId = c.ParentId
//	if c.NoCache == 0 {
//		model.NoCache = constant.Yes
//	}
//	model.Component = c.Component
//	model.Visible = c.Visible
//	if c.Visible == 0 {
//		model.Visible = constant.Yes
//	}
//	model.IsFrame = c.IsFrame
//	if c.IsFrame == 0 {
//		model.IsFrame = constant.No
//	}
//	authId := token.AuthId(ctx)
//	model.UpdateBy = authId
//	return model
//}
//
//func (c *MenuUpdateActionReq) Generate(model *models.SysMenu, ctx http.Context) *models.SysMenu {
//	model.MenuName = c.MenuName
//	model.Sort = c.Sort
//	model.Status = c.Status
//	model.Permission = c.Permission
//	model.ParentId = c.ParentId
//	authId := token.AuthId(ctx)
//	model.UpdateBy = authId
//	return model
//}
